// See https://sequelize.org/master/manual/model-basics.html
// for more of what you can do here.
// 这个才是真正的书籍管理
// 这个才是真正的书籍管理
import { Sequelize, DataTypes, Model } from 'sequelize';
import { Application } from '../declarations';
import { HookReturn } from 'sequelize/types/hooks';

export default function (app: Application): typeof Model {
  const sequelizeClient: Sequelize = app.get('sequelizeClient');
  const booksinfo = sequelizeClient.define('booksinfo', {
    // 书名
    name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 其他名
    otherName: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 作者
    author: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 语言
    lang: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 出版社
    press: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 定价
    price: {
      type: DataTypes.FLOAT,
      allowNull: false
    },
    // 分类
    class: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 简介
    introduction: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 备注
    desc: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 馆藏位置：一号馆 - 一楼 - N区 - N架 - N层
    Included: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 状态：已借出/正常在馆
    state: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 借阅人
    people: {
      type: DataTypes.STRING,
      allowNull: true
    },
    // 限制：是否能离馆
    restrict: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 来源：捐赠/采购...
    source: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 操作人员
    operation: {
      type: DataTypes.STRING,
      allowNull: false
    }
  }, {
    hooks: {
      beforeCount(options: any): HookReturn {
        options.raw = true;
      }
    }
  });

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  (booksinfo as any).associate = function (models: any): void {
    // Define associations here
    // See https://sequelize.org/master/manual/assocs.html
  };

  return booksinfo;
}
